package com.feihong.txgw.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.feihong.txgw.R;
import com.feihong.txgw.adapter.Holder.BaseViewHolder;
import com.feihong.txgw.adapter.Holder.SharePlatformViewHolder;
import com.feihong.txgw.inter.listener.share.ShareTypeListener;
import com.feihong.txgw.model.bean.share.SharePlatformEntity;

import java.util.ArrayList;

/**
 * @name txgw_app
 * @class name：com.feihong.txgw.adapter
 * @class describe:
 * @author wangziheng
 * @time 2017/9/18 11:29
 * @change
 * @chang time
 * @class describe
 */
public class SharePlatformAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private ArrayList<SharePlatformEntity> mPlatforms;
    private Context mContext;

    public SharePlatformAdapter(Context context) {
        mContext = context;
        mPlatforms = new ArrayList<>();
    }

    public void setPlatform(ArrayList<SharePlatformEntity> platforms){
        mPlatforms = platforms;
        notifyDataSetChanged();
    }
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SharePlatformViewHolder(LayoutInflater.from(mContext).inflate(R.layout.share_platform__item_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        final SharePlatformEntity sharePlatformEntity = mPlatforms.get(position);
        SharePlatformViewHolder mHolder = (SharePlatformViewHolder) holder;
        mHolder.initData(sharePlatformEntity);
        ((SharePlatformViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mShareTypeListener.setOnShareItemListener(sharePlatformEntity);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mPlatforms.size();
    }

    private ShareTypeListener mShareTypeListener;
    public void setOnShareListener(ShareTypeListener shareListener){
        mShareTypeListener = shareListener;
    }
}
